﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class OrderTime
    {
        private readonly Chain.IDAL.OrderTime dal = new Chain.IDAL.OrderTime();

        public int Add(Chain.Model.OrderTime model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.OrderTime> DataTableToList(DataTable dt)
        {
            List<Chain.Model.OrderTime> list = new List<Chain.Model.OrderTime>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.OrderTime item = new Chain.Model.OrderTime();
                    if ((dt.Rows[i]["OrderTimeID"] != null) && (dt.Rows[i]["OrderTimeID"].ToString() != ""))
                    {
                        item.OrderTimeID = int.Parse(dt.Rows[i]["OrderTimeID"].ToString());
                    }
                    if ((dt.Rows[i]["OrderTimeCode"] != null) && (dt.Rows[i]["OrderTimeCode"].ToString() != ""))
                    {
                        item.OrderTimeCode = dt.Rows[i]["OrderTimeCode"].ToString();
                    }
                    if ((dt.Rows[i]["OrderMemID"] != null) && (dt.Rows[i]["OrderMemID"].ToString() != ""))
                    {
                        item.OrderMemID = int.Parse(dt.Rows[i]["OrderMemID"].ToString());
                    }
                    if ((dt.Rows[i]["OrderToken"] != null) && (dt.Rows[i]["OrderToken"].ToString() != ""))
                    {
                        item.OrderToken = dt.Rows[i]["OrderToken"].ToString();
                    }
                    if ((dt.Rows[i]["OrderMarchTime"] != null) && (dt.Rows[i]["OrderMarchTime"].ToString() != ""))
                    {
                        item.OrderMarchTime = DateTime.Parse(dt.Rows[i]["OrderMarchTime"].ToString());
                    }
                    if ((dt.Rows[i]["OrderState"] != null) && (dt.Rows[i]["OrderState"].ToString() != ""))
                    {
                        if ((dt.Rows[i]["OrderState"].ToString() == "1") || (dt.Rows[i]["OrderState"].ToString().ToLower() == "true"))
                        {
                            item.OrderState = true;
                        }
                        else
                        {
                            item.OrderState = false;
                        }
                    }
                    if ((dt.Rows[i]["OrderOutTime"] != null) && (dt.Rows[i]["OrderOutTime"].ToString() != ""))
                    {
                        item.OrderOutTime = DateTime.Parse(dt.Rows[i]["OrderOutTime"].ToString());
                    }
                    if ((dt.Rows[i]["OrderStartUserID"] != null) && (dt.Rows[i]["OrderStartUserID"].ToString() != ""))
                    {
                        item.OrderStartUserID = int.Parse(dt.Rows[i]["OrderStartUserID"].ToString());
                    }
                    if ((dt.Rows[i]["OrderEndUserID"] != null) && (dt.Rows[i]["OrderEndUserID"].ToString() != ""))
                    {
                        item.OrderEndUserID = int.Parse(dt.Rows[i]["OrderEndUserID"].ToString());
                    }
                    if ((dt.Rows[i]["OrderCreateTime"] != null) && (dt.Rows[i]["OrderCreateTime"].ToString() != ""))
                    {
                        item.OrderCreateTime = DateTime.Parse(dt.Rows[i]["OrderCreateTime"].ToString());
                    }
                    if ((dt.Rows[i]["OrderShopID"] != null) && (dt.Rows[i]["OrderShopID"].ToString() != ""))
                    {
                        item.OrderShopID = int.Parse(dt.Rows[i]["OrderShopID"].ToString());
                    }
                    if ((dt.Rows[i]["OrderProjectID"] != null) && (dt.Rows[i]["OrderProjectID"].ToString() != ""))
                    {
                        item.OrderProjectID = int.Parse(dt.Rows[i]["OrderProjectID"].ToString());
                    }
                    if ((dt.Rows[i]["OrderRulesID"] != null) && (dt.Rows[i]["OrderRulesID"].ToString() != ""))
                    {
                        item.OrderRulesID = int.Parse(dt.Rows[i]["OrderRulesID"].ToString());
                    }
                    if ((dt.Rows[i]["OrderRemark"] != null) && (dt.Rows[i]["OrderRemark"].ToString() != ""))
                    {
                        item.OrderRemark = dt.Rows[i]["OrderRemark"].ToString();
                    }
                    if ((dt.Rows[i]["OrderPredictTime"] != null) && (dt.Rows[i]["OrderPredictTime"].ToString() != ""))
                    {
                        item.OrderPredictTime = Convert.ToDecimal(dt.Rows[i]["OrderPredictTime"]);
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int OrderTimeID)
        {
            return this.dal.Delete(OrderTimeID);
        }

        public bool DeleteList(string OrderTimeIDlist)
        {
            return this.dal.DeleteList(OrderTimeIDlist);
        }

        public bool Exists(int OrderTimeID)
        {
            return this.dal.Exists(OrderTimeID);
        }

        public bool ExistsProject(int ProjectID)
        {
            return this.dal.ExistsProject(ProjectID);
        }

        public bool ExistsRules(int RulesID)
        {
            return this.dal.ExistsRules(RulesID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, out resCount, strWhere);
        }

        public int GetMaxId()
        {
            return this.dal.GetMaxId();
        }

        public Chain.Model.OrderTime GetModel(int OrderTimeID)
        {
            return this.dal.GetModel(OrderTimeID);
        }

        public List<Chain.Model.OrderTime> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool isUse(int Project)
        {
            return this.dal.isUse(Project);
        }

        public bool Update(Chain.Model.OrderTime model)
        {
            return this.dal.Update(model);
        }
    }
}

